﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace NFAPI
{
    public abstract class Item
    {
        private List<string> _genres = new List<string>();

        [XPath("/catalog_title/id/text()")]
        [XPath("/queue_item/id/text()")]
        [XPath("/filmography_item/id/text()")]
        public string Id { get; set; }

        [XPath("/catalog_title/title/@short")]
        [XPath("/queue_item/title/@short")]
        [XPath("/filmography_item/title/@short")]
        public string TitleShort { get; set; }

        [XPath("/queue_item/title/@regular")]
        [XPath("/catalog_title/title/@regular")]
        [XPath("/filmography_item/title/@regular")]
        public string Title { get; set; }

        [XPath("/catalog_title/box_art")]
        [XPath("/queue_item/box_art")]
        [XPath("/filmography_item/box_art")]
        public BoxArt Art { get; set; }

        [XPath("/catalog_title/link[@rel='http://schemas.netflix.com/catalog/titles/synopsis']")]
        [XPath("/queue_item/link[@title='synopsis']")]
        [XPath("/filmography_item/link[@rel='http://schemas.netflix.com/catalog/titles/synopsis']")]
        public Link Synopsis { get; set; }

        [XPath("/catalog_title/release_year/text()")]
        [XPath("/queue_item/release_year/text()")]
        [XPath("/filmography_item/release_year/text()")]
        public int ReleaseYear { get; set; }

        [XPath("/catalog_title/category[@scheme='http://api.netflix.com/categories/mpaa_ratings' or @scheme='http://api.netflix.com/categories/tv_ratings'][1]/@label")]
        [XPath("/queue_item/category[@scheme='http://api.netflix.com/categories/mpaa_ratings' or @scheme='http://api.netflix.com/categories/tv_ratings'][1]/@label")]
        [XPath("/filmography_item/category[@scheme='http://api.netflix.com/categories/mpaa_ratings' or @scheme='http://api.netflix.com/categories/tv_ratings'][1]/@label")]
        public Rating Rating { get; set; }

        [XPath("/catalog_title/category[@scheme='http://api.netflix.com/categories/genres']/@label")]
        [XPath("/queue_item/category[@scheme='http://api.netflix.com/categories/genres']/@label")]
        [XPath("/filmography_item/category[@scheme='http://api.netflix.com/categories/genres']/@label")]
        public List<string> Genres
        {
            get { return _genres; }
            set { _genres = value; }
        }

        public string Genre
        {
            get { return _genres[0]; }
        }

        [XPath("/catalog_title/link[@rel='http://schemas.netflix.com/catalog/people.cast']")]
        [XPath("/queue_item/link[@title='cast']")]
        [XPath("/filmography_item/link[@rel='http://schemas.netflix.com/catalog/people.cast']")]
        public Link Cast { get; set; }

        [XPath("/queue_item/link[@title='directors']")]
        [XPath("/catalog_title/link[@rel='http://schemas.netflix.com/catalog/people.directors']")]
        [XPath("/filmography_item/link[@rel='http://schemas.netflix.com/catalog/people.directors']")]
        public Link Directors { get; set; }

        [XPath("/catalog_title/link[@rel='http://schemas.netflix.com/catalog/titles/format_availability']")]
        [XPath("/queue_item/link[@title='formats']")]
        [XPath("/filmography_item/link[@rel='http://schemas.netflix.com/catalog/titles/format_availability']")]
        public Link Formats { get; set; }

        [XPath("/catalog_title/link[@rel='http://schemas.netflix.com/catalog/titles/screen_formats']")]
        [XPath("/queue_item/link[@title='screen formats']")]
        public Link ScreenFormats { get; set; }

        [XPath("/catalog_title/link[@rel='http://schemas.netflix.com/catalog/title/languages_and_audio']")]
        [XPath("/queue_item/link[@title='languages and audio']")]
        [XPath("/filmography_item/link[@rel='http://schemas.netflix.com/catalog/titles/languages_and_audio']")]
        public Link LanguagesAndAudio { get; set; }

        [XPath("/catalog_title/average_rating/text()")]
        [XPath("/queue_item/average_rating/text()")]
        [XPath("/filmography_item/average_rating/text()")]
        public float AverageRating { get; set; }

        [XPath("/catalog_title/link[@rel='http://schemas.netflix.com/catalog/titles.similars']")]
        [XPath("/queue_item/link[@title='similars']")]
        [XPath("/filmography_item/link[@rel='http://schemas.netflix.com/catalog/titles.similars']")]
        public Link Similars { get; set; }

        [XPath("/catalog_title/link[@title='webpage']")]
        [XPath("/queue_item/link[@title='web page']")]
        [XPath("/filmography_item/link[@title='web page']")]
        public Link Webpage { get; set; }

        [XPath("/queue_item/link[@title='awards']")]
        [XPath("/filmography_item/link[@rel='http://schemas.netflix.com/catalog/titles/awards']")]
        [XPath("/catalog_title/link[@rel='http://schemas.netflix.com/catalog/titles/awards']")]
        public Link Awards { get; set; }

        [XPath("/queue_item/link[@title='previews']")]
        public Link Previews { get; set; }

        public abstract string TitleRef { get; }
    }
}
